package com.atguigu;

import java.util.Random;

public class Test01 {
	// public Point point =new Point();
	public static void main(String[] args) {
		test01();
	}
	public static void test01() {
		// --------------堆内存不足就会像内存进行申请----------------
		// -Xms6m -Xmx20m -XX:+PrintGCDetails
		// 机器内存大小的4分之1
//		 System.out.println("max memory:" +
//		 (Runtime.getRuntime().maxMemory()/1024/1024)+"MB");
		// 机器内存大小的64分之1
//		 System.out.println("total memory:" +
//		 (Runtime.getRuntime().totalMemory()/1024/1024)+"MB");

		// 查看GC信息
		System.out.println("max memory:" + Runtime.getRuntime().maxMemory());
		System.out.println("free memory:" + Runtime.getRuntime().freeMemory());
		System.out.println("total memory:" + Runtime.getRuntime().totalMemory());


		byte[] b1 = new byte[1 * 1024 * 1024];
		System.out.println("分配了1M");
		System.out.println("max memory:" + Runtime.getRuntime().maxMemory());
		System.out.println("free memory:" + Runtime.getRuntime().freeMemory());
		System.out.println("total memory:" + Runtime.getRuntime().totalMemory());

		byte[] b2 = new byte[6 * 1024 * 1024];
		System.out.println("分配了6M");
		System.out.println("max memory:" + Runtime.getRuntime().maxMemory());
		System.out.println("free memory:" + Runtime.getRuntime().freeMemory());
		System.out.println("total memory:" + Runtime.getRuntime().totalMemory());
	}

	public static void test02() {
		//-Xms8m -Xmx8m -XX:+PrintGCDetails
		//minor GC 和full GC触发
		String str = "www.atguigu.com";
		while (true) {
			str += str + new Random().nextInt(88888888) + new Random().nextInt(999999999);
		}
	}

}